package com.qf.zhijia.zhijiasearch.utils;


import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author 岳鹏
 * @Date 2020/9/9
 */
@Configuration
public class ESClient {
    @Value("${elasticsearch.host}")
    String host;

    @Value("${elasticsearch.port}")
    Integer port;

    @Bean
    public RestHighLevelClient restHighLevelClient(){
        //创建HttpHost
        HttpHost httpHost = new HttpHost(host,port);
        //创建RestClientBuilder
        RestClientBuilder restClientBuilder = RestClient.builder(httpHost);

        //创建RestHighLeveClient
        RestHighLevelClient client = new RestHighLevelClient(restClientBuilder);

        return client;
    }


}
